The last thing a mobile user wants to do is type on a
mobile keyboard, but it is inevitable for many applications to require
some form of text input. In this section I discuss keyboard capabilities
and API enhancements to ease typing on the keyboard on Windows Phone 7
devices.
1. Physical Keyboard
Windows Phone 7 devices may
also have a hardware slide-out keyboard, but your application will not
pass certification in App Hub if it is dependent upon the hardware
keyboard. Otherwise, from a software development perspective,
programming for hardware keyboard input "just works." Of the six devices
available at Windows Phone 7 launch, only one had a full slide-out
keyboard, and another had a vertical QWERTY keyboard. The other four
devices were pure touch devices without a physical keyboard.
2. Soft Input Panel (SIP) Keyboard
All Windows Phone 7 devices have
a SIP keyboard used for entering text. Typing on the SIP keyboard built
into Windows Phone 7 is a pretty comfortable means of entering text;
however, it is still a small keyboard, so anything that a developer can
do to ease typing can really help improve the overall user experience.
3. Programming with the Keyboard
Typing text on a mobile
phone should be minimized as much as possible, but if text input is
required, a developer should take advantage of capabilities to make
typing as simple as possible. In the next section I cover InputScope,
which is a must-have feature to take advantage of when typing is
required in your Windows Phone 7 applications.
When testing keyboard
input, you will be tempted to type on your PC keyboard; however, it does
not work. You must use the mouse with the SIP keyboard in the Emulator
for input.
Click the Pause/Break button on
your PC keyboard to enable typing in the emulator with your PC keyboard
instead of having to use the mouse to "touch" the SIP.
|
|
3.1. InputScope
The InputScope property is available on the TextBox control, which is the primary control for text input. InputScope
lets the developer customize the keyboard for the expected type of
input. For example, the default behavior is that when you click into a
TextBox, the SIP keyboard pops up, as shown in Figure 1.
The second TextBox has an InputScope of Text, which enables word selection just above the keyboard, as shown in Figure 2.
With just one simple attribute, text input becomes much easier for the enduser. Figure 3 shows three additional text input options, which I explain just after the figure.
Configuring an InputScope of Search
turns the Enter key into a GO key with the idea that the user enters a
search keyword and then clicks Enter to kick off a search. Password is
not actually an InputScope. It is a custom TextBox class named PasswordBox that automatically hides data entry as the user types. An InputScope of TelephoneNumber
brings up a phone keypad. As you can see, all of these could come in
handy as you develop your application UI and optimize input for the end
user. Table 1
lists the available InputScope options and their descriptions,
reprinted here for your convenience from the Windows Phone 7
documentation.
Table 1. Available InputScope Options
Input Scope | Description |
---|
AddressCity | The text input pattern for a city address. |
AddressCountryName | The text input pattern for the name of a country/region. |
AddressCountryShortName | The text input pattern for the abbreviated name of a country/region. |
dAdressStateOrProvince | The text input pattern for a state or province. |
AddressStreet | The text input pattern for a street address. |
AlphanumericFullWidth | The text input pattern for alphanumeric full-width characters (East-Asian languages only). |
AlphanumericHalfWidth | The text input pattern for alphanumeric half-width characters(East-Asian languages only). |
Chat | The SIP layout for text messaging, which recognizes pre-defined abbreviations. Supported only in Silverlight for Windows Phone. |
CurrencyAmount | The text input pattern for amount of currency. |
CurrencyAmountAndSymbol | The text input pattern for amount and symbol of currency. |
CurrencyChinese | The text input pattern for Chinese currency. |
Date | The text input pattern for a calendar date. |
DateDay | The text input pattern for the numeric day in a calendar date. |
DateDayName | The text input pattern for the name of the day in a calendar date. |
DateMonth | The text input pattern for the numeric month in a calendar date. |
DateMonthName | The text input pattern for the name of the month in a calendar date. |
DateYear | The text input pattern for the year in a calendar date. |
Default | The default handling of input commands. |
Digits | The text input pattern for digits. |
EmailNameOrAddress | The SIP layout for an e-mail name or address. Supported only in Silverlight for Windows Phone. |
EmailSmtpAddress | The text input pattern for a Simple Mail Transfer Protocol (SMTP) e-mail address. |
EmailUserName | The text input pattern for an e-mail user name. |
FileName | The text input pattern for a file name. |
FullFilePath | The text input pattern for the full path of a file. |
Hanja | The text input pattern for Hanja characters (Korean characters). |
Hiragana | The text input pattern for the Hiragana writing system(a Japanese syllabary). |
KatakanaFullWidth | The text input pattern for full-width Katakana characters (a Japanese syllabary). |
KatakanaHalfWidth | The text input pattern for half-width Katakana characters (a Japanese syllabary). |
LogOnName | The text input pattern for a log on name. |
Maps | The SIP layout for entering a map location. Supported only in Silverlight for Windows Phone. |
NameOrPhoneNumber | The SIP layout for SMS To field. Supported only in Silverlight for Windows Phone. |
Number | The text input pattern for a number. |
NumberFullWidth | The text input pattern for a full-width number. |
OneChar | The text input pattern for one character. |
Password | The text input pattern for a password. |
PersonalFullName | The text input pattern for a person's full name. |
PersonalGivenName | The text input pattern for a person's given name. |
PersonalMiddleName | The text input pattern for a person's middle name. |
PersonalNamePrefix | The text input pattern for the prefix of a person's name. |
PersonalNameSuffix | The text input pattern for the suffix of a person's name. |
PersonalSurname | The text input pattern for a person's surname. |
PhraseList | The text input pattern for a phrase list. |
PostalAddress | The text input pattern for a postal address. |
PostalCode | The text input pattern for a postal code. |
RegularExpression | The text input pattern for a regular expression. |
Search | The SIP layout for a search query. Supported only in Silverlight for Windows Phone. |
Srgs | The text input pattern for the Speech Recognition Grammar Specification (SRGS). |
TelephoneAreaCode | The text input pattern for a telephone area code. |
TelephoneCountryCode | The text input pattern for a telephone country/region code. |
TelephoneLocalNumber | The text input pattern for a telephone local number. |
TelephoneNumber | The text input pattern for a telephone number. |
Text | The software input panel (SIP) layout for standard text input. Supported only in Silverlight for Windows Phone. |
Time | The text input pattern for the time. |
TimeHour | The text input pattern for the hour of the time. |
TimeMinorSec | The text input pattern for the minutes or seconds of time. |
Url | The text input pattern for a Uniform Resource Locator (URL). |
Xml | The text input pattern for XML. |
Let's now shift gears and explore the available keyboard events.
3.2. Keyboard Events
There are two keyboard events available on the TextBox, as well as pretty much any other object that inherits from UIElement: the KeyDown and KeyUp events. Both events have a KeyEventArgs class in its parameters that provides access to the Key and PlatformKeyCode values native to the platform. It also provides access to the OriginalSource
property that represents the control that raised the Keyboard event, as
well as a Handled member to indicate that the key has been processed.
This completes our
discussion of keyboard events. In general, typing should be minimized in
a mobile application for the reasons listed previously, i.e., small
screen, small keyboard, and so on. Mobile devices are optimized for
touch input, especially modern devices with highly responsive capacitive
touch screens that do not require a stylus. Let's now focus on touch
input.